package com.micro.school.system.service.impl;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.system.api.domain.vo.MerMerchantVos;
import com.micro.school.system.domain.MerMerchant;
import com.micro.school.system.domain.SchoolPayWay;
import com.micro.school.system.mapper.MerMerchantMapper;
import com.micro.school.system.mapper.SchoolPayWayMapper;
import com.micro.school.system.service.MerMerchantService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

import java.util.Date;
import java.util.List;

/**
 * (MerMerchant)表服务实现类
 *
 * @author makejava
 * @since 2025-08-08 19:07:19
 */
@Service("merMerchantService")
public class MerMerchantServiceImpl implements MerMerchantService {
    @Resource
    private MerMerchantMapper merMerchantMapper;

    @Resource
    private SchoolPayWayMapper schoolPayWayMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MerMerchant queryById(Integer id) {
        return this.merMerchantMapper.queryById(id, SecurityContextHolder.getUserTenantId());
    }

    @Override
    public MerMerchantVos queryMerchantById(Long id) {
        return merMerchantMapper.queryMerchantById(id,SecurityContextHolder.getUserTenantId());
    }

    @Override
    public MerMerchantVos merMerchant(Integer id) {
        return this.merMerchantMapper.merMerchant(id, SecurityContextHolder.getUserTenantId());
    }



    /**
     * 分页查询
     *
     * @param merMerchant 筛选条件
     * @param
     * @return 查询结果
     */
    @Override
    public List<MerMerchant> queryByPage(MerMerchant merMerchant) {
        merMerchant.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        return this.merMerchantMapper.queryAllByLimit(merMerchant);
    }

    /**
     * 新增数据
     *
     * @param merMerchant 实例对象
     * @return 实例对象
     */
    @Override
    public MerMerchant insert(MerMerchant merMerchant) {
        merMerchant.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        SchoolPayWay schoolPayWay = schoolPayWayMapper.queryById(merMerchant.getPayWayId(), SecurityContextHolder.getUserTenantId());
        merMerchant.setPayWayName(schoolPayWay.getPayWayName());
        merMerchant.setUpdateTime(new Date());
        merMerchant.setCreateTime(new Date());
        this.merMerchantMapper.insert(merMerchant);
        return merMerchant;
    }

    /**
     * 修改数据
     *
     * @param merMerchant 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(MerMerchant merMerchant) {
        merMerchant.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        merMerchant.setUpdateTime(new Date());
        return this.merMerchantMapper.update(merMerchant) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return true;
    }
}
